(function(pageName){
  sugarcane.module[pageName] = function(){
    $('.j-pagescreen').addClass('fn-hide');
    var urlParams = sugarcane.getUrlParams(),
      docType = urlParams['docType'] || 1,
      columnName = decodeURI(urlParams['columnname']),
      themeId = urlParams['themeId'],
      columnId = urlParams['columnid'];
    if ($('#j-screen-'+pageName+columnId).length) {
      var pageScreen = $('#j-screen-'+pageName+columnId);
      pageScreen.removeClass('fn-hide');
      var _scrollTop = pageScreen.data('scrolltop') || 0;
      setTimeout(function(){
        $(window).scrollTop(_scrollTop);
      }, 10);
      return false;
    }
    var pageScreen = $('<div class="j-pagescreen" id="j-screen-'+pageName+columnId+'"></div>');
    $('body').append(pageScreen);

    var listObj = $('<div></div>'),
      moreObj = $('<div class="app-listmore"></div>');
    pageScreen.append(listObj);
    pageScreen.append(moreObj);

    var listPage = 0,
      listLoading = false;
    columnShow();

    moreObj.on(tap, function(){
      if (!listLoading) {
        moreObj.html('正在加载更多...');
        columnShow();
      }
    });
    
    // 获取主题栏目列表
    function columnShow(){
      listLoading = true;
      listPage ++;
      sugarcane.ajaxApi({
        "url": "/special/columnNewsList",
        "data": {"columnId": columnId, "current": listPage},
        "callback": function(res){
          listLoading = false;
          if (res['hasMore']) {
            moreObj.html('点击加载更多');
          } else {
            moreObj.remove();
          }
          if (res['code'] == 0) {

            //document.title = res.data.title || columnName; 
            sugarcane.twoShare({
              "id": res.data.id || themeId,
              "title": res.data.title || columnName,
              "desc": '分享来自经济日报客户端，更多精彩请下载http://d.jingjiribao.cn/index.html',
              "imgUrl": res.data.shareImage || 'https://static-jjrb.xinhuaapp.com/base/logo.png',
              "link": res.data.shareUrl,
              "docType": docType
            });
            if (res['data'] && res['data'].length) {
              var columnData = res['data'];
              sugarcane.module.load('listitem', function(listitemFn){
                $.each(columnData, function(){
                  var _obj = listitemFn(this);
                  listObj.append(_obj);
                  // 点击新闻详情
                  var _detailHref = 'detail.html?id='+this['id'];
                  _obj.on(tap, function(){
                    pageScreen.data('scrolltop', $(window).scrollTop());
                    sugarcane.route.location({
                      'href': _detailHref
                    });
                  });
                });
              });

              // shareBanner();
              // sugarcane['shareBanner']({
              //   'newsId': newsId,
              //   'id': columnId,
              //   'docType': docType,
              //   'containObj': pageScreen 
              // });
            }
          } else {
            showerrorView();
            peach.hiddenAppbar();
            // alert(res['message']);
          }
        }
      });
    }

    // function shareBanner(){
    //   if(sugarcane['app']['isShare'] && !pageScreen.find('.app-banner').length ){
    //     sugarcane.module.load('banner', function(listitemFn){
    //       var bannerObj = listitemFn({'id': id, 'docType': docType});
    //       pageScreen.append(bannerObj);
    //       var _height = $(bannerObj).css('height');
    //       pageScreen.css('margin-bottom',_height);
    //     });

    //   }
    // }

    function showerrorView(){
      var clientHeight = document.documentElement.clientHeight;
      pageScreen.css('position','relative').css('height',clientHeight+'px');
      var errorviewObj = $(`<div class="app-errorview">
          <img class="img" src="/static/img/isempty.png">
        <p class="error-tip">暂时没有数据</p>
      </div>`);
       pageScreen.append(errorviewObj);
    }
  };

  sugarcane.module['state'][pageName] = 'load';
  sugarcane.module.callback(pageName);
}('specialcolumn'));
